var mongoose=require('./sqlModels');

var goodsSchema = new mongoose.Schema({
    id:Number,
    imgSrc:String,
    price:Number,
    type:String,
    src1:String,
    src2:String,
    disSrc1:String,
    disSrc2:String,
    disSrc3:String,
    disSrc:String,
    rouler:String,
    title:String,
    sale:Number
});

var goodsModel = mongoose.model('products',goodsSchema);
//获取
exports.getList=function (callback) {
    goodsModel.find({},function (err,docs) {
        if(err){
            throw err;
        }else {
            callback(docs);
        }
    })
};
//添加
exports.add = function (article,callback) {
    goodsModel.create(article,function (err) {
        if(err){
            callback(false);
        }else {
            callback(true);
        }
    })
};

//删除
exports.delete = function (condition,callback) {
    goodsModel.create(condition,function (err) {
        if(err){
            callback(false);
        }else {
            callback(true);
        }
    })
};
//修改
exports.edit = function (condition,updateData,callback) {
    goodsModel.update(condition,updateData, {multi: true,overwrite:true},function (err) {
        if(err){
            callback(false)
        }else {
            callback(true)
        }
    })
};

